import { useReducer } from 'react'

function reducer (init, action) {
  console.log(init, action)
  if (action.type === 'age') {
    return { ...init, age: action.payload }
  } else if (action.type === 'name') {
    return { ...init, name: action.payload }
  }
  return init
}
export default function useRedux () {
  const [state, dispatch] = useReducer(reducer, { name: '小花', age: 10 })
  return {
    state, dispatch
  }
}
